<template>
  <div class="student">
    <h1>学校名称：{{ name }}</h1>
    <h1>学校地址：{{ address }}</h1>
    <h1>接收School组件传递过来的数据{{ schoolData }}</h1>
  </div>
</template>

<script>

export default {
  name: "Student",
  data() {
    return {
      name: "尚硅谷",
      address: "衡阳",
      schoolData: ""
    }
  },
  mounted() {
    this.$eventBus.$on("getData", ({name, age}) => {
      this.schoolData = name + age
      console.log(name, age)
    })

    /*this.$eventBus.$on("getData",function ({name,age}){
      console.log(this) //this指向的School组件
      console.log(name,age)
    })*/
  },
  beforeDestroy() {
    this.$eventBus.$off("getData")
  }
};
</script>

<style>
.student {
  background-color: #DC143C;
}
</style>
